//
//  ClassMeetingViewController.m
//  TeamInformatization
//
//  Created by bigger on 2019/4/1.
//  Copyright © 2019年 SPIC. All rights reserved.
//

#import "ClassMeetingViewController.h"
#import "CommonMessageViewCell.h"
#import "CommonMessage.h"
#import "CreateClassMeetingViewController.h"
#import "CreatAfterWorkMeetingViewController.h"

@interface ClassMeetingViewController () <ChangeContentViewDelegate, UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *classMeetingTableView;

@property (nonatomic, strong) NSMutableArray *meetingListArray;

// 创建按钮
@property (nonatomic, strong) UIButton *creatMeetButton;

@end

@implementation ClassMeetingViewController

{
    int _currentType;//(0.班前会 1.班后会 2.工前会)
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self showTitleBarWithTitle:@"我的会议" leftButtonStyle:Base_NavigationBar_Back rightButtonStyle:Base_NavigationBar_None];
    // 初始数据
    _currentType = 0;
    
    self.meetingListArray = [NSMutableArray arrayWithCapacity:0];
    for (int i = 0; i < 7; i++) {
        CommonMessage *message = [[CommonMessage alloc] init];
        message.title = @"会议";
        message.subTitle1 = @"所在班组";
        message.subTitle2 = @"参加人员";
        message.date = @"2019-03-25 09:40:23";
        message.contentStr1 = @"扎矿-检修三车间-点检五单元班组";
        message.contentStr2 = @"张三李四王五等";
        
        [self.meetingListArray addObject:message];
    }
    
    [self requestMeetingData];
    
    
    [self loadShowViews];
}


// Data
- (void)requestMeetingData
{
    
    [AFNRequest cookGetWithURL:kMyBeforeMeeting params:nil success:^(id json) {
        
        alertWithTitleMeaage(@"访问成功", json[@"text"]);
        
    } failure:^(NSError *error) {
        
    }];

}





// UI
- (void)loadShowViews
{
    ChangeContentView *changeContentView = [[ChangeContentView alloc] initWithFrame:CGRectMake(0, kSafeAreaTopHeight, kScreenWidth, 40 * kScaleWidth) TitleArray:@[@"班前会", @"班后会", @"工前会"]];
    changeContentView.delegate = self;
    [self.view addSubview:changeContentView];
    
    self.classMeetingTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kSafeAreaTopHeight + 40 * kScaleWidth, kScreenWidth, kSecondContentHeight - 40 * kScaleWidth) style:UITableViewStylePlain];
    [_classMeetingTableView registerClass:[CommonMessageViewCell class] forCellReuseIdentifier:@"CommonMessage"];
    _classMeetingTableView.delegate = self;
    _classMeetingTableView.dataSource = self;
    _classMeetingTableView.backgroundColor = [UIColor clearColor];
    _classMeetingTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _classMeetingTableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_classMeetingTableView];
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 59 * kScaleWidth)];
    footerView.backgroundColor = kCommonBGGaryColor;
    _classMeetingTableView.tableFooterView = footerView;
    
    // 创建按钮
    self.creatMeetButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_creatMeetButton setCommonStyleAndShowText:@"创建班前会"];
    [self.view addSubview:_creatMeetButton];
    [_creatMeetButton addTarget:self action:@selector(creatMeetButton:) forControlEvents:UIControlEventTouchUpInside];
    [_creatMeetButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-15 * kScaleWidth);
        make.centerX.mas_equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(kScreenWidth - 30 * kScaleWidth, 44 * kScaleWidth));
    }];
    
}



#pragma mark - ChangeContentViewDelegate
- (void)getTouchNum:(int)touchNum withChangeContentView:(ChangeContentView *)changeContentView
{
    _currentType = touchNum;
    
    _creatMeetButton.tag = 100+touchNum;
    switch (touchNum) {
        case 0: {
            [_creatMeetButton setTitle:@"创建班前会" forState:UIControlStateNormal];
            break;
        }
        case 1: {
            [_creatMeetButton setTitle:@"创建班后会" forState:UIControlStateNormal];
            break;
        }
        case 2: {
            break;
        }
            
        default:
            break;
    }
    
    [self upadteViewUI];
}

#pragma mark - TableViewDelegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _meetingListArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 152 * kScaleWidth;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
        CommonMessage *commonMessage = [[CommonMessage alloc] init];
        if (_meetingListArray.count != 0) {
            commonMessage = self.meetingListArray[indexPath.row];
        }
    
    CommonMessageViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonMessage" forIndexPath:indexPath];
    if (!cell) {
        cell = [[CommonMessageViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CommonMessage"];
    }
    
    [cell setShowCellWithCommonMessage:commonMessage];
    
    return cell;

    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

//更新页面UI
- (void)upadteViewUI{
    
    if (_currentType == 2) {
        _creatMeetButton.hidden = YES;
    } else {
        _creatMeetButton.hidden = NO;
    }
}
#pragma -导航栏 两边按钮操作
-(void)baseNavigationBarLeftButtonClick:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)baseNavigationBarRightButtonClick:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 点击按钮创建班前会 班后会
-(void)creatMeetButton:(UIButton *)sender {
    if (sender.tag == 102) {
    } else if (sender.tag == 101) {//班后会
        NSLog(@"班后会");
        
        CreatAfterWorkMeetingViewController *vc = [[CreatAfterWorkMeetingViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    } else {//班前会
        CreateClassMeetingViewController *vc = [[CreateClassMeetingViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
